home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / macgambit-20-compiler-src-p2 / Thomas / rep.scm < prev    next >
Encoding:
Text File  |  1994-07-26  |  5.3 KB  |  137 lines  |  [TEXT/gamI]

  1. (##declare (standard-bindings))
  2. ;*              Copyright 1992 Digital Equipment Corporation
  3. ;*                         All Rights Reserved
  4. ;*
  5. ;* Permission to use, copy, and modify this software and its documentation is
  6. ;* hereby granted only under the following terms and conditions.  Both the
  7. ;* above copyright notice and this permission notice must appear in all copies
  8. ;* of the software, derivative works or modified versions, and any portions
  9. ;* thereof, and both notices must appear in supporting documentation.
  10. ;*
  11. ;* Users of this software agree to the terms and conditions set forth herein,
  12. ;* and hereby grant back to Digital a non-exclusive, unrestricted, royalty-free
  13. ;* right and license under any changes, enhancements or extensions made to the
  14. ;* core functions of the software, including but not limited to those affording
  15. ;* compatibility with other hardware or software environments, but excluding
  16. ;* applications which incorporate this software.  Users further agree to use
  17. ;* their best efforts to return to Digital any such changes, enhancements or
  18. ;* extensions that they make and inform Digital of noteworthy uses of this
  19. ;* software.  Correspondence should be provided to Digital at:
  20. ;*
  21. ;*                      Director, Cambridge Research Lab
  22. ;*                      Digital Equipment Corp
  23. ;*                      One Kendall Square, Bldg 700
  24. ;*                      Cambridge MA 02139
  25. ;*
  26. ;* This software may be distributed (but not offered for sale or transferred
  27. ;* for compensation) to third parties, provided such third parties agree to
  28. ;* abide by the terms and conditions of this notice.
  29. ;*
  30. ;* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  31. ;* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  32. ;* MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  33. ;* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  34. ;* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  35. ;* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  36. ;* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  37. ;* SOFTWARE.
  38.  
  39. ; $Id: portable-rep.scm,v 1.8 1992/09/21 21:30:56 birkholz Exp $
  40.  
  41. ;;; Just use current (user?) environment and keep a list of known module
  42. ;;; variables in thomas-rep-module-variables.
  43.  
  44. (define thomas-rep-module-variables '())
  45.  
  46. (define (empty-thomas-environment!)
  47.   ;; Just dump thomas-rep-module-variables.
  48.   (set! thomas-rep-module-variables '()))
  49.  
  50. (define (thomas-rep)
  51.   (dylan::catch-all-conditions
  52.    (lambda ()
  53.      (let loop ()
  54.        (newline)
  55.        (display "? ")
  56.        (let ((input (read)))
  57.          (newline)
  58.          (if (and (eq? input 'thomas:done))
  59.              'thomas:done
  60.              (compile-expression
  61.               input '!MULTIPLE-VALUES thomas-rep-module-variables
  62.               (lambda (new-vars preamble compiled-output)
  63.                 (implementation-specific:eval
  64.                  `(BEGIN
  65.                     ,@preamble
  66.                     (LET* ((!MULTIPLE-VALUES (VECTOR '()))
  67.                            (!RESULT ,compiled-output))
  68.                       (IF (EQ? !RESULT !MULTIPLE-VALUES)
  69.                           (LET RESULT-LOOP
  70.                               ((COUNT 1)
  71.                                (RESULTS (VECTOR-REF !MULTIPLE-VALUES 0)))
  72.                             (IF (PAIR? RESULTS)
  73.                                 (LET ((RESULT (CAR RESULTS)))
  74.                                   (NEWLINE)
  75.                                   (DISPLAY ";Value[")(DISPLAY COUNT)
  76.                                   (DISPLAY "]: ")(WRITE RESULT)
  77.                                   (RESULT-LOOP (+ 1 COUNT) (CDR RESULTS)))
  78.                                 (NEWLINE)))
  79.                           (BEGIN
  80.                             (NEWLINE)(DISPLAY ";Value: ")(WRITE !RESULT)
  81.                             (NEWLINE))))))
  82.                 (set! thomas-rep-module-variables
  83.                       (append new-vars thomas-rep-module-variables))
  84.                 (loop)))))))))
  85.  
  86.  
  87.  
  88. ; Gambit specific read-eval-print loop (errors throw back to the toplevel).
  89.  
  90. (define thomas-repl-continuation #f)
  91.  
  92. (define initial-debug-repl ##debug-repl)
  93.  
  94. (set! ##debug-repl
  95.   (lambda (error-cont)
  96.     (let ((repl-cont thomas-repl-continuation))
  97.       (if repl-cont
  98.         (begin
  99.           (##write-string "*** Going back to Thomas toplevel..." (##repl-out))
  100.           (##newline (##repl-out))
  101.           (repl-cont #f))
  102.         (initial-debug-repl error-cont)))))
  103.  
  104. (define (run-thomas)
  105.  
  106.   (##newline (##repl-out))
  107.   (##write-string "Entering Thomas read-eval-print-loop." (##repl-out))
  108.   (##newline (##repl-out))
  109.   (##write-string "Exit by typing \"thomas:done\"" (##repl-out))
  110.   (##newline (##repl-out))
  111.  
  112.   (call-with-current-continuation
  113.     (lambda (k)
  114.       (set! thomas-repl-continuation k)))
  115.  
  116.   (thomas-rep)
  117.  
  118.   (set! thomas-repl-continuation #f)
  119.  
  120.   (##write-string "Returning to Scheme. Type (run-thomas) to go back to Thomas." (##repl-out))
  121.   (##newline (##repl-out)))
  122.  
  123.  
  124. ; Startup:
  125.  
  126. (display "Thomas 1.1 system running on MacGambit 2.0") (newline)
  127. (newline)
  128. (display "Copyrights:") (newline)
  129. (display "  Thomas: (c) 1992, Digital Equipment Corporation") (newline)
  130. (display "  MacGambit: (c) 1992-93, Universite de Montreal") (newline)
  131. (newline)
  132. (display "Check the file \"Thomas.README\" for details") (newline)
  133.  
  134. (run-thomas)
  135.  
  136. (##repl)
  137.